/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.jeesite.modules.pile.entity;

import javax.validation.constraints.NotBlank;
import org.hibernate.validator.constraints.Length;
import javax.validation.constraints.NotNull;
import java.util.Date;
import com.jeesite.common.mybatis.annotation.JoinTable;
import com.jeesite.common.mybatis.annotation.JoinTable.Type;
import com.fasterxml.jackson.annotation.JsonFormat;

import com.jeesite.common.entity.DataEntity;
import com.jeesite.common.mybatis.annotation.Column;
import com.jeesite.common.mybatis.annotation.Table;
import com.jeesite.common.mybatis.mapper.query.QueryType;

/**
 * 停车桩Entity
 * @author 谢宇燊
 * @version 2020-04-05
 */
@Table(name="pile", alias="a", columns={
		@Column(name="id", attrName="id", label="停车桩ID", isPK=true),
		@Column(name="area", attrName="area", label="停车桩位置", queryType=QueryType.LIKE),
		@Column(name="pile_num", attrName="pileNum", label="停车桩代号", queryType=QueryType.LIKE),
		@Column(name="piles", attrName="piles", label="停车桩分布", isQuery=false),
		@Column(name="piles_count", attrName="pilesCount", label="单个区域停车桩总数", isQuery=false),
		@Column(name="piles_available", attrName="pilesAvailable", label="单个区域空停车桩数量", isQuery=false),
		@Column(name="piles_unavailabe", attrName="pilesUnavailabe", label="单个区域非空停车桩数量", isQuery=false),
		@Column(name="piles_status", attrName="pilesStatus", label="停车桩状态", isQuery=false),
		@Column(name="created_time", attrName="createdTime", label="创建时间", isQuery=false),
		@Column(name="create_by", attrName="createBy", label="创建者", isUpdate=false, isQuery=false),
		@Column(name="updated_by", attrName="updatedBy", label="更新者", isQuery=false),
		@Column(name="updated_time", attrName="updatedTime", label="更新时间", isQuery=false),
		@Column(name="remarks", attrName="remarks", label="备注", queryType=QueryType.LIKE),
	}, orderBy="a.id DESC"
)
public class Pile extends DataEntity<Pile> {
	
	private static final long serialVersionUID = 1L;
	private String area;		// 停车桩位置
	private String pileNum;		// 停车桩代号
	private String piles;		// 停车桩分布
	private Integer pilesCount;		// 单个区域停车桩总数
	private Integer pilesAvailable;		// 单个区域空停车桩数量
	private Integer pilesUnavailabe;		// 单个区域非空停车桩数量
	private Integer pilesStatus;		// 停车桩状态
	private Date createdTime;		// 创建时间
	private String updatedBy;		// 更新者
	private Date updatedTime;		// 更新时间
	
	public Pile() {
		this(null);
	}

	public Pile(String id){
		super(id);
	}
	
	@NotBlank(message="停车桩位置不能为空")
	@Length(min=0, max=500, message="停车桩位置长度不能超过 500 个字符")
	public String getArea() {
		return area;
	}

	public void setArea(String area) {
		this.area = area;
	}
	
	@NotBlank(message="停车桩代号不能为空")
//	@Length(min=0, max=255, message="停车桩代号长度不能超过 255 个字符")
	@Length(min=3, max=3, message="停车桩代号长度必须为 3 个字符")

	public String getPileNum() {
		return pileNum;
	}

	public void setPileNum(String pileNum) {
		this.pileNum = pileNum;
	}
	
	@Length(min=0, max=500, message="停车桩分布长度不能超过 500 个字符")
	public String getPiles() {
		return piles;
	}

	public void setPiles(String piles) {
		this.piles = piles;
	}
	
	@NotNull(message="单个区域停车桩总数不能为空")
	public Integer getPilesCount() {
		return pilesCount;
	}

	public void setPilesCount(Integer pilesCount) {
		this.pilesCount = pilesCount;
//    实现新增逻辑
//    this.pilesAvailable = pilesCount;
//    this.pilesUnavailabe = 0;
		this.setPilesAvailable(pilesCount);
		this.setPilesUnavailabe(0);
		//修改了逻辑，自动生成车桩分布（0是空，1是有车，每5个加一个','）
		String piles2="";
		for (int i=1;i<=pilesCount;i++){
			piles2+=0;
			if (i%5==0)
				piles2+=',';
		}
        this.setPiles(piles2);
	}

	
	public Integer getPilesAvailable() {
		return pilesAvailable;
	}

	public void setPilesAvailable(Integer pilesAvailable) {
		this.pilesAvailable = pilesAvailable;
	}
	
	public Integer getPilesUnavailabe() {
		return pilesUnavailabe;
	}

	public void setPilesUnavailabe(Integer pilesUnavailabe) {
		this.pilesUnavailabe = pilesUnavailabe;
	}
	
	public Integer getPilesStatus() {
		return pilesStatus;
	}

	public void setPilesStatus(Integer pilesStatus) {
		this.pilesStatus = pilesStatus;
	}
	
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	public Date getCreatedTime() {
		return createdTime;
	}

	public void setCreatedTime(Date createdTime) {
		this.createdTime = createdTime;
	}
	
	@Length(min=0, max=64, message="更新者长度不能超过 64 个字符")
	public String getUpdatedBy() {
		return updatedBy;
	}

	public void setUpdatedBy(String updatedBy) {
		this.updatedBy = updatedBy;
	}
	
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	public Date getUpdatedTime() {
		return updatedTime;
	}

	public void setUpdatedTime(Date updatedTime) {
		this.updatedTime = updatedTime;
	}
	
}